from fastapi import APIRouter, Body
from typing import Annotated
from starlette.responses import JSONResponse
from application.util.ResponseUtil import ResponseUtil
from application.enumeration.StatisticsTypeEnum import StatisticsTypeEnum
from application.enumeration.ContentTypeEnum import ContentTypeEnum
from application.logic import CommonLogic

# 创建路由
router: APIRouter = APIRouter(prefix="/common", tags=["通用"])


@router.post("/email_captcha", summary="发送邮箱验证码")
def email_captcha(email: str) -> JSONResponse:
    """
    发送邮箱验证码
    :param email: 邮箱
    :return: JSONResponse
    """
    CommonLogic.email_captcha(email=email)
    return ResponseUtil().success()


@router.post("/add_statistics", summary="添加文章统计")
async def add_statistics(target_id: Annotated[int, Body(embed=True)],
                         content_type: Annotated[ContentTypeEnum, Body(embed=True)] = ContentTypeEnum.NOTE,
                         statistics_type: Annotated[StatisticsTypeEnum, Body(embed=True)] = StatisticsTypeEnum.LIKE
                         ) -> JSONResponse:
    """
    添加文章统计
    :param target_id: 目标ID
    :param content_type: 内容类型
    :param statistics_type: 统计类型
    :return: JSONResponse
    """
    await CommonLogic.add_statistics(target_id=target_id, content_type=content_type, statistics_type=statistics_type)
    return ResponseUtil().success()
